package com.bcmusic.distri.controller;

import com.bcmusic.distri.pojo.DistributeConstract;
import com.bcmusic.distri.service.DistributeConstractService;
import com.github.pagehelper.PageInfo;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/****
 * @Author:admin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/distributeConstract")
@CrossOrigin
public class DistributeConstractController {

    @Autowired
    private DistributeConstractService distributeConstractService;

    /***
     * DistributeConstract分页条件搜索实现
     * @param distributeConstract
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false) DistributeConstract distributeConstract, @PathVariable  int page, @PathVariable  int size){
        //调用DistributeConstractService实现分页条件查询DistributeConstract
        PageInfo<DistributeConstract> pageInfo = distributeConstractService.findPage(distributeConstract, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * DistributeConstract分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用DistributeConstractService实现分页查询DistributeConstract
        PageInfo<DistributeConstract> pageInfo = distributeConstractService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param distributeConstract
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<DistributeConstract>> findList(@RequestBody(required = false) DistributeConstract distributeConstract){
        //调用DistributeConstractService实现条件查询DistributeConstract
        List<DistributeConstract> list = distributeConstractService.findList(distributeConstract);
        return new Result<List<DistributeConstract>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Integer id){
        //调用DistributeConstractService实现根据主键删除
        distributeConstractService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改DistributeConstract数据
     * @param distributeConstract
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody DistributeConstract distributeConstract, @PathVariable Integer id){
        //设置主键值
        distributeConstract.setConstractId(id);
        //调用DistributeConstractService实现修改DistributeConstract
        distributeConstractService.update(distributeConstract);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增DistributeConstract数据
     * @param distributeConstract
     * @return
     */
    @PostMapping
    public Result add(@RequestBody DistributeConstract distributeConstract){
        //调用DistributeConstractService实现添加DistributeConstract
        distributeConstractService.add(distributeConstract);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询DistributeConstract数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<DistributeConstract> findById(@PathVariable Integer id){
        //调用DistributeConstractService实现根据主键查询DistributeConstract
        DistributeConstract distributeConstract = distributeConstractService.findById(id);
        return new Result<DistributeConstract>(true,StatusCode.OK,"查询成功",distributeConstract);
    }

    /***
     * 查询DistributeConstract全部数据
     * @return
     */
    @GetMapping
    public Result<List<DistributeConstract>> findAll(){
        //调用DistributeConstractService实现查询所有DistributeConstract
        List<DistributeConstract> list = distributeConstractService.findAll();
        return new Result<List<DistributeConstract>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
